﻿using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZhuXingFamilys.Fileupload
{
    public class UploadLoadFamily : IExternalEventHandler
    {
        public string Familyfullpath { set; get; }
        public Bitmap Familyimage { set; get; }
        Family family = null;
        public void Execute(UIApplication app)
        {
            UIDocument uidoc = app.ActiveUIDocument;
            Document doc = uidoc.Document;
            Transaction transaction = new Transaction(doc); //事务
            transaction.Start("载入族");
            bool b = doc.LoadFamily(Familyfullpath, out family);

            FamilySymbol setOfSymbols = doc.GetElement(family.GetFamilySymbolIds().First()) as FamilySymbol;
            Familyimage = setOfSymbols.GetPreviewImage(new Size(100, 100));
            transaction.Commit();
        }

        public string GetName()
        {
            return "UploadLoadFamily";
        }
    }
}
